/*
 Xern Entity Relocation Network
 Copyright (C) 2010-2011 Ronie Salgado <roniesalg@gmail.com>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
*/

#include <OgreCamera.h>
#include "Camera.hpp"

namespace XernOgre
{
	Camera::Camera(Ogre::SceneManager *scene, Ogre::Camera *camera)
		: scene(scene), camera(camera)
	{
		camera->setNearClipDistance(0.1);
		camera->setFarClipDistance(300.0);
		id = nil_uuid();
	}

	Camera::~Camera()
	{
		scene->destroyCamera(camera);
	}

	IResource::ResourceFlags Camera::GetFlags() const
	{
		return RFL_MOVABLE_OBJECT;
	}

	void Camera::UpdateState(boost::shared_ptr<IDataFilter> stateData)
	{
	}

	const uuid &Camera::GetId() const
	{
		return this->id;
	}

	void Camera::SetId(const uuid &id)
	{
		this->id = id;
	}

	float Camera::GetNearDistance() const
	{
		return camera->getNearClipDistance();
	}

	void Camera::SetNearDistance(float distance)
	{
		camera->setNearClipDistance(distance);
	}

	float Camera::GetFarDistance() const
	{
		return camera->getFarClipDistance();
	}

	void Camera::SetFarDistance(float distance)
	{
		camera->setFarClipDistance(distance);
	}

	float Camera::GetFOV() const
	{
		return camera->getFOVy().valueDegrees();
	}

	void Camera::SetFOV(float fov)
	{
		camera->setFOVy(Ogre::Degree(fov));
	}

	Ogre::Camera *Camera::GetOgreCamera()
	{
		return camera;
	}

	Ogre::MovableObject *Camera::GetMovable()
	{
		return camera;
	}

	void Camera::DelayAttach(boost::shared_ptr<SceneNode> node)
	{
	}

	void Camera::SetTransform(const ReversibleTransform &trans)
	{
		transform = trans;

		const Vector3 &pos = trans.GetVector();
		const Quaternion &quat = trans.GetRotation();
		camera->setPosition(pos.x, pos.y, pos.z);
		camera->setOrientation(Ogre::Quaternion(quat.w, quat.x, quat.y, quat.z));
	}

	const ReversibleTransform &Camera::GetTransform() const
	{
		return transform;
	}

}; // namespace XernOgre
